package com.lys.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lys.commonutils.R;
import com.lys.eduservice.entity.EduCourse;
import com.lys.eduservice.entity.chapter.chapterVo;
import com.lys.eduservice.entity.frontvo.CourseQueryVo;
import com.lys.eduservice.entity.frontvo.CourseWebVo;
import com.lys.eduservice.service.EduChapterService;
import com.lys.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Lyyyys
 * @version 1.0
 * @date 2021/6/20 22:28
 */
@Api(description="前端讲师列表分页")
@RestController
@RequestMapping("/eduservice/coursefront")
@CrossOrigin
public class CourseFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduChapterService chapterService;

    @ApiOperation(value = "分页查询课程")
    @PostMapping("getCourseFrontList/{page}/{limit}")
    public R getCourseFrontList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,
            @ApiParam(name = "courseQuery", value = "查询对象", required = false)
            @RequestBody(required = false) CourseQueryVo courseQuery){
        Page<EduCourse> pageParam = new Page<EduCourse>(page, limit);
        Map<String, Object> map = courseService.pageListWeb(pageParam, courseQuery);
        return  R.ok().data("map",map);
    }

    @ApiOperation(value = "课程详情")
    @GetMapping("getCourseFrontInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId){
        //根据课程id，查询上半部分课程信息返回前端页面
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(courseId);

        //根据课程id查询章节和小节
        List<chapterVo> chapterVideoList = chapterService.getChapterVideo(courseId);

        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVideoList);
    }

}
